import { getJghParam, getJghList } from '@/services/law';

export default {
  namespace: 'regulatoryLetters',

  state: {
    jghParamData: {},
    jghListData: {},
  },

  effects: {
    *getParam({ payload }, { call, put }) {
      try {
        const response = yield call(getJghParam, payload);
        yield put({
          type: 'setJghParam',
          payload: {
            jghParamData: response,
          },
        });
      } catch (e) {
        console.log('Error:', e);
      }
    },
    *getList({ payload }, { call, put }) {
      try {
        const response = yield call(getJghList, payload);
        yield put({
          type: 'setJghList',
          payload: {
            jghListData: response.data,
          },
        });
      } catch (e) {
        console.log('Error:', e);
      }
    },
  },
  reducers: {
    setJghParam(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
    setJghList(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
  },
};
